package com.imyuanma.qingyun.common.factory;

import com.imyuanma.qingyun.interfaces.common.model.BaseDO;
import com.imyuanma.qingyun.interfaces.common.model.enums.ETrashFlagEnum;

import java.util.Date;
import java.util.Map;

/**
 * BaseDO构建
 *
 * @author wangjy
 * @date 2022/05/21 18:12:06
 */
public class BaseDOBuilder {

    /**
     * 填充BaseDO
     *
     * @param baseDO 基础模型
     */
    public static void fillBaseDOForInsert(BaseDO baseDO) {
        baseDO.setCreateTime(new Date());
        baseDO.setUpdateTime(new Date());
        baseDO.setCreateUserId(1L);
        baseDO.setUpdateUserId(1L);
        baseDO.setDataSequence(1L);
        baseDO.setDataVersion(1L);
        baseDO.setTrashFlag(ETrashFlagEnum.VALID.getType());
    }

    /**
     * 填充BaseDO
     *
     * @param condition 基础模型
     */
    public static void fillMapForInsert(Map<String, Object> condition) {
        condition.put("createTime", new Date());
        condition.put("updateTime", new Date());
        condition.put("createUserId", 1L);
        condition.put("updateUserId", 1L);
        condition.putIfAbsent("dataSequence", 1L);
        condition.putIfAbsent("dataVersion", 1L);
        condition.putIfAbsent("trashFlag", ETrashFlagEnum.VALID.getType());
    }

    /**
     * 填充BaseDO
     *
     * @param baseDO 基础模型
     */
    public static void fillBaseDOForUpdate(BaseDO baseDO) {
        baseDO.setUpdateTime(new Date());
        baseDO.setUpdateUserId(1L);
    }

    /**
     * 填充BaseDO
     *
     * @param condition 基础模型
     */
    public static void fillMapForUpdate(Map<String, Object> condition) {
        condition.put("updateTime", new Date());
        condition.put("updateUserId", 1L);
    }
}
